    var forum  = null;
    var count  = null;
    var offset = null;

    $(document).ready(function(){
        initParam();
        setStyle("topic");
        
        if ( offset == "0" ){
            $("#a_head_l").hide();
        }else{
            $("#a_head_l").show();
        }
       
        $.mobile.loading('show');
        var http = "http://anibox.me/api.php?task=get_forum_topics&forum="+forum+"&offset="+offset+"&count="+count;
        $.getJSON(http, parseJson);
    }); 
    
    //initialization params
    function initParam(){
        forum = getParam("id");
        var befoPage = window.localStorage.getItem("befoPage");
        if (befoPage == "mainforum"){
            offset = 0
            window.localStorage.setItem("topOffset", offset);
        }else{
            offset = window.localStorage.getItem("topOffset");
        }
        
        count = getListCount();
        
        console.log('forim '+forum+' offset '+offset+' count '+count);
    }
    
    //parse data in list
    function parseJson(data){
    	console.log(data.length);
        if (data.length == 0){
            offset = parseInt(offset) - parseInt(count);
            window.localStorage.setItem("topOffset", offset);
            $('#a_head_r').hide();
            var http = "http://anibox.me/api.php?task=updates&type="+forum+"&offset="+offset+"&count="+count;
            $.getJSON(http, parseJson);
            return;
        }
        
        if(data.length < count){
            $('#a_head_r').hide();
        }
        
        for (var i in data) {
        	console.log(data[i].title);
            $('#list').append(
                '<li id="' + data[i].id + '&answers='+data[i].answers+'" onClick="liOnClick(this.id);">' +
                
                
                '<div class="div_style_update" style="font-weight:bold;">'+
                 data[i].title +
                 '</div>'+
                 '<p>Автор: <font color="red">'+  data[i].author+'</font>'+
                 ' Просмотров: '+data[i].hits+
                 ' Дата: '+parseUnixTimeStamp(data[i].date)+'</p>'+
                 
                 '<span class="ui-li-count">'+data[i].answers+'</span>'+
                 
                '</li>\n'
            );
        }
        $('#list').listview('refresh');
        $.mobile.loading('hide');
    }
    
    //click list
    function liOnClick(id){
        goToPage("messages.html?id="+id);
    }
    
    //click in head befo
    function updateBefo(){
        var int = parseInt(offset) - parseInt(count);
        if (int == 0)
            $("#a_head_l").hide();
        if(int < 0){
            $("#a_head_l").hide();
            return "";
        }
        else{
            $('#a_head_r').show();
            $('#list').empty();
            offset   = int;
            var http = "http://anibox.me/api.php?task=get_forum_topics&forum="+forum+"&offset="+offset+"&count="+count;
            $.mobile.loading('show');
            $.getJSON(http, parseJson);
            window.scrollTo(0, 0);
            window.localStorage.setItem("topOffset", offset);
        } 
    }
    
    //click in head next
    function updateNext(){
        $("#a_head_l").show();
        $('#list').empty();
        offset = parseInt(offset) + parseInt(count);
        var http = "http://anibox.me/api.php?task=get_forum_topics&forum="+forum+"&offset="+offset+"&count="+count;
        $.mobile.loading('show');
        $.getJSON(http, parseJson); 
        window.scrollTo(0, 0);
        window.localStorage.setItem("topOffset", offset);
    }